package com.shop.admincontroller;

import com.shop.entity.SysRole;
import com.shop.entity.SysUser;
import com.shop.service.SysRoleService;
import com.shop.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.Version;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

/**
 * @version 1.0
 * @author  huangfei
 */
@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @ApiOperation("查询所有角色")
    @GetMapping("/listRoles")
    public ResultUtils findAllRole(){
        List<SysRole> allRole = sysRoleService.findAllRole();
        return  ResultUtils.ok(allRole);
    }

    @ApiOperation("新增角色资源授权")
    @RequiresRoles(value = {"admin"})
    @GetMapping("/saveRoleSysPerssion")
    public ResultUtils saveRoleSysPerssion(SysRole sysRole,@RequestParam(value = "perssionId") List<Integer> perssionId){
        ResultUtils resultUtils = sysRoleService.insertRolePerssion(sysRole, perssionId);
        return  resultUtils;
    }

    @ApiOperation("删除角色和权限")
    @RequiresRoles(value = {"admin"})
    @GetMapping("/deleteRoleSysPerssion")
    public ResultUtils deleteRoleSysPerssion(Integer roleId){
        ResultUtils resultUtils = sysRoleService.deleteRoleSysPerssion(roleId);
        return  resultUtils;
    }


    @ApiOperation("修改角色有的权限")
    @RequiresRoles(value = {"admin"})
    @GetMapping("/updateRoleSysPerssion")
    public ResultUtils updateRoleSysPerssion(SysRole sysRole, @RequestParam(value = "roleId",required = false) List<Integer> roleId){
        ResultUtils resultUtils = sysRoleService.updateRoleSysPerssion(sysRole,roleId);
        return  resultUtils;
    }

    @ApiOperation("查询角色有的权限")
    @RequiresRoles(value = {"admin"})
    @GetMapping("/findRoleSysPerssion")
    public ResultUtils findRoleSysPerssion(@ApiParam(value = "用户名") @RequestParam(required = false)  String roleName,
                                           @ApiParam(value = "当前页数") @RequestParam(required = false)Integer current,
                                           @ApiParam(value = "每页显示多少条") @RequestParam(required = false) Integer size){
        ResultUtils resultUtils = sysRoleService.findRoleSysPerssion(roleName,current,size);
        return  resultUtils;
    }











}
